package slowka;

/**
 * Class representing one question in test
 * @author ssobczak
 */
public class Question {
    public Question(String g, Translation t) {
        category = g;
        question = t.getFrom().getWord();
        answer = t.getTo().getWord();
        mistakes = 0;
        repeatsLeft = 1;
    }

    public String getCategory() {
        return category;
    }

    public String getQuestion() {
        return question;
    }
    public String getAnswer() {
        return question + " = " + answer;
    }

    /**
     * Checks if enough good answers were given
     * @return true if question can be deleted
     */
    public boolean canDelete() {
        return repeatsLeft == 0;
    }

    /**
     *
     * @return true if there was no mistake
     */
    public boolean isPerfect() {
        return mistakes == 0;
    }

    /** How many repeats is left */
    public int getRepeatsLeft() {
        return repeatsLeft;
    }

    /** How many mistakes was made */
    public int getMistakes() {
        return mistakes;
    }

    /**
     * Checks the answer and updates internal statistics
     * @param a answer to check
     * @return true is a cis correct answer
     */
    public boolean checkAnswer(String a) {
        if(!answer.contentEquals(a)) {
            mistakes++;
            repeatsLeft++;
            return false;
        }
        else {
            repeatsLeft--;
            return true;
        }
    }

    private String category, question, answer;
    private int mistakes, repeatsLeft;
}
